import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.bdware.doip.endpoint.server.DoipListenerConfig;
import org.bdware.doip.endpoint.server.DoipServiceInfo;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

public class triffle {

    @Test
    public void doipserviceInfoSerial(){

        DoipListenerConfig conf = new DoipListenerConfig("tcp://127.0.0.1:8001","2.1");
        ArrayList<DoipListenerConfig> list = new ArrayList<>();
        list.add(conf);

//        conf = new DoipListenerConfig("udp://127.0.0.1:8001","2.1");
        list.add(new DoipListenerConfig("udp://127.0.0.1:8001","2.1"));

        DoipServiceInfo info = new DoipServiceInfo("id","owner","repo",list);
        info.serviceName = "NaME";
        info.serviceDescription = "DESC";
        info.publicKey = "pk";

        String infoStr = new Gson().toJson(info);

        System.out.println(new Gson().toJson(info));

        DoipServiceInfo info1 = new Gson().fromJson(infoStr,
                new TypeToken<DoipServiceInfo>(){}.getType());

        System.out.println(info1.listenerInfos.get(0).url);

    }


    @Test
    public void readFromFile() throws FileNotFoundException {

        Reader infoStrReader = new FileReader("./config/serverConf.json");

        DoipServiceInfo info1 = new Gson().fromJson(infoStrReader,
                new TypeToken<DoipServiceInfo>(){}.getType());

        System.out.println(new Gson().toJson(info1));
    }



}
